package gameapi;

import java.util.Collections;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.NoneScoped;
import javax.faces.bean.SessionScoped;

import org.apache.log4j.Logger;

import db.RegisteredUserDb;

/**
 * Class representing a player playing in a {@link Game}.
 */
@ManagedBean(name = "player")
@NoneScoped
public class Player {
	
	private static Logger logger = Logger.getLogger(Player.class);
	/**
	 * The name of this user
	 */
	private String name;

	/**
	 * The current position of the user's counter
	 */
	private int position;

	/**
	 * Sequence of fields in the game the player has to cover
	 */
	private List<Integer> route;

	private boolean isLoggedIn = false;

	@ManagedProperty(value="password")
	private String password;
	private String userName;
	@ManagedProperty(value="birthdate")
	private String birthdate;
	private String lastName;
	private String sex;
	private int lastDiceResult = 0;
	

	/**
	 * Initializes a {@link Player} with the specified <code>name</code>.
	 * 
	 * @param name
	 *            to set
	 */
	public Player() {
		super();
	}

	public int getLastDiceResult() {
		return lastDiceResult;
	}

	public void setLastDiceResult(int lastDiceResult) {
		this.lastDiceResult = lastDiceResult;
	}

	public void setName(String name) {
		System.out.println("Name" + name);
		this.name = name;
	}

	/**
	 * Returns the name of this player.
	 * 
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Return the actual position of this player's counter
	 * 
	 * @return the actual position of this player's counter
	 */
	public int getPosition() {
		return this.position;
	}

	/**
	 * Sets the actual position of this player's counter
	 * 
	 * @param pos
	 *            actual position of this player's counter
	 */
	public void setPosition(int pos) {
		this.position = pos;
	}

	/**
	 * Get the sequence of fields the player has to cover
	 * 
	 * @return the sequence of fields the player has to cover
	 */
	public List<Integer> getRoute() {
		return Collections.unmodifiableList(this.route);
	}

	/**
	 * Set the sequence of fields the player has to cover
	 * 
	 * @param route
	 *            sequence of fields the player has to cover
	 */
	public void setRoute(List<Integer> route) {
		this.route = route;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getBirthdate() {
		return birthdate;
	}

	public void setBirthdate(String birthdate) {
		System.out.println("birthday set");
		this.birthdate = birthdate;
	}

	public String getUserName() {
//		logger.debug("getUserName: " + userName);
		return userName;
	}

	public void setUserName(String userName) {
		logger.debug("setUserName: "+ userName);
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public boolean isLoggedIn() {
		return isLoggedIn;
	}

	public void setLoggedIn(boolean isLoggedIn) {
		this.isLoggedIn = isLoggedIn;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getSex() {
		return sex;
	}

}
